home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / msdos / plotting / pcgplots / gptscrol.cpp < prev    next >
C/C++ Source or Header  |  1992-04-24  |  5KB  |  194 lines

  1. // GptScroll.cpp
  2. // copyright 1992 Pittsburgh Supercomputing Center
  3. #include "gpt.h"
  4.  
  5.  // Scroller Constructor
  6. Scroller::Scroller(WindowPt win, short xMax, short yMax)
  7.     {
  8.     RECT rect;
  9.     FullSize = FALSE;
  10.     nVscrollPos  = nHscrollPos = 0;
  11.     MaxX = xMax;
  12.     MaxY = yMax;
  13.     XRatio = 1.0;
  14.    YRatio = 1.0;
  15.     this->win = win;
  16.     this->hWnd  = win->GetHandle();
  17.     GetClientRect( hWnd, (LPRECT) &rect );
  18.     ixMax        = MaxX - rect.right;
  19.     iyMax        = MaxY - rect.bottom;
  20.     ixMin = 0;
  21.     iyMin = 0;
  22.     //GetClipBox(hDC, lpRect)
  23.     SetScrollRange(hWnd,SB_HORZ,ixMin,ixMax,FALSE);    // triggers size message
  24.     SetScrollPos(hWnd,SB_HORZ,nHscrollPos, FALSE);
  25.     SetScrollRange(hWnd,SB_VERT,iyMin,iyMax,FALSE);
  26.     SetScrollPos(hWnd,SB_VERT,nVscrollPos, FALSE);
  27.  
  28.  
  29.     }
  30. /* *****************
  31. void Scroller::NewSize(short x, short y)
  32.     {
  33.     //MaxX=1024; MaxY = 714;
  34.     ixMax        = MaxX - x;
  35.     iyMax        = MaxY - y;
  36.  
  37.     BOOL repaint;
  38.     repaint = FALSE;
  39.     if (iyMax  < GetSystemMetrics(SM_CYHSCROLL)*XRatio && iyMax > 0)
  40.         {repaint = TRUE; iyMax = 0; }
  41.     nVscrollPos = max(0, min(nVscrollPos, iyMax));
  42.     SetScrollRange(hWnd,SB_VERT,0,iyMax,repaint);
  43.     SetScrollPos(hWnd,SB_HORZ,nHscrollPos, repaint);
  44.  
  45.     repaint = FALSE;
  46.     if (ixMax  < GetSystemMetrics(SM_CXVSCROLL)*YRatio && ixMax > 0)
  47.         { repaint = TRUE; ixMax = 0; }
  48.  
  49.     nHscrollPos = max(0, min(nHscrollPos, ixMax));
  50.     SetScrollRange(hWnd,SB_HORZ,0,ixMax, repaint);
  51.     SetScrollPos(hWnd,SB_HORZ,nHscrollPos, repaint);
  52.     if (ixMax== 0 && iyMax == 0) FullSize = TRUE;
  53.     else FullSize = FALSE;
  54.     }
  55. *********************************** */
  56.  void Scroller::NewSize(short x, short y)
  57.     {
  58.     float XPRat = 1.0;
  59.     float YPRat = 1.0;
  60.     if ( ixMax)
  61.         XPRat = (float)(ixMax - nHscrollPos ) /(ixMax -ixMin);
  62.         // P = max - (max - min)*R
  63.         // R = (max - P) / (max - min)
  64.     if (iyMax)
  65.         YPRat = (float)(iyMax - nVscrollPos ) /(iyMax - iyMin);
  66.     int SizeX = MaxX - x;     // Scroll Range in X ( == 0 at full size )
  67.     int SizeY = MaxY - y;     // Scroll Range in Y ( == 0 at full size )
  68.  
  69.     // Siz = Max - Min
  70.     // Rat = (Pos - Min) / Siz
  71.     // Min = Pos - Rat*Siz
  72.     if (ixMax == ixMin) nHscrollPos = 0;
  73.     else  nHscrollPos = (float)nHscrollPos/(ixMax - ixMin) * SizeX;
  74.     if (iyMax == iyMin) nVscrollPos = 0;
  75.     else  nVscrollPos = (float)nVscrollPos/(iyMax - iyMin) * SizeY;
  76.  
  77.     ixMax = nHscrollPos  + (XPRat*SizeX);
  78.     iyMax = nVscrollPos  + (YPRat*SizeY);
  79.     if (ixMax > SizeX)  ixMax = SizeX;
  80.     if (iyMax > SizeY) iyMax = SizeY;
  81.     ixMin = ixMax - SizeX;
  82.     iyMin = iyMax - SizeY;
  83.     if (ixMin < 0) ixMin = 0;
  84.     if (iyMin < 0) iyMin = 0;
  85.     BOOL repaint;
  86.     repaint = FALSE;
  87.     if (iyMax  < GetSystemMetrics(SM_CYHSCROLL)*XRatio )
  88.         {repaint = TRUE; iyMax = 0; }
  89.     // Determine where position currently is relative to size
  90.     nVscrollPos = max(0, min(nVscrollPos, iyMax));
  91.     nVscrollPos = min( max(nVscrollPos, iyMin), iyMax);
  92.     SetScrollRange(hWnd,SB_VERT,iyMin,iyMax,repaint);
  93.     SetScrollPos(hWnd,SB_VERT,nVscrollPos, repaint);
  94.  
  95.     repaint = FALSE;
  96.     if (ixMax  < GetSystemMetrics(SM_CXVSCROLL)*YRatio )
  97.         { repaint = TRUE; ixMax = 0; }
  98.  
  99.     nHscrollPos = max(0, min(nHscrollPos, ixMax));
  100.     nHscrollPos = min( max(nHscrollPos, ixMin), ixMax);
  101.     SetScrollRange(hWnd,SB_HORZ,ixMin,ixMax, repaint);
  102.     SetScrollPos(hWnd,SB_HORZ,nHscrollPos, repaint);
  103.     if (!SizeX && !SizeY) FullSize = TRUE;
  104.     else FullSize = FALSE;
  105.     }
  106.  
  107.  
  108.  void Scroller::SetPos(short horz, short vert)
  109.     {
  110.     if (horz > ixMax) horz = ixMax;
  111.     if (horz < ixMin) horz = ixMin;
  112.     if (vert > iyMax) vert = iyMax;
  113.     if (vert < iyMin) vert = iyMin;
  114.  
  115.     //nHscrollPos = max(0, min(horz, ixMax));
  116.     //nVscrollPos = max(0, min(vert, ixMax));
  117.     nHscrollPos = horz;
  118.     nVscrollPos = vert;
  119.     SetScrollPos(hWnd,SB_VERT, nVscrollPos,TRUE);
  120.     SetScrollPos(hWnd,SB_HORZ, nHscrollPos,TRUE);
  121.     }
  122.  void Scroller::Scroll()
  123.     {
  124.     WORD wScrollType      = ((FrameWindowPt)win)->GetwParam();
  125.     WORD wScrollDirection = ((FrameWindowPt)win)->GetiMessage();
  126.     WORD wThumbPosition   = LOWORD(((FrameWindowPt)win)->GetlParam() );
  127.     short iPos;
  128.     short inc;
  129.     RECT rect;
  130.     GetClientRect( hWnd, (LPRECT) &rect );
  131.  
  132.     if (wScrollDirection == WM_VSCROLL)
  133.         {
  134.         iPos = nVscrollPos;
  135.         inc  = (iyMax - iyMin)/10+1;
  136.         }
  137.     else
  138.         {
  139.         iPos = nHscrollPos;
  140.         inc  = (ixMax - ixMin)/10+1;
  141.         }
  142.     switch ( wScrollType)
  143.         {
  144.         case SB_LINEUP:
  145.         iPos -=inc;
  146.         break;
  147.  
  148.         case SB_LINEDOWN:
  149.         iPos +=inc;
  150.         break;
  151.  
  152.         case SB_PAGEUP:
  153.         iPos -= inc*3;
  154.         break;
  155.  
  156.         case SB_PAGEDOWN:
  157.         iPos += inc*3;
  158.         break;
  159.  
  160.         case SB_THUMBPOSITION:
  161.         iPos = wThumbPosition;
  162.         break;
  163.  
  164.         default:
  165.         break;
  166.         }
  167.     if (wScrollDirection == WM_VSCROLL)
  168.         {
  169.         if (iPos > iyMax) iPos = iyMax;
  170.         if (iPos < iyMin) iPos = iyMin;
  171.         nVscrollPos = iPos;
  172.         if (nVscrollPos != GetScrollPos(hWnd, SB_VERT))
  173.             {
  174.             SetScrollPos(hWnd,SB_VERT, nVscrollPos,TRUE);
  175.             InvalidateRect(hWnd, NULL, TRUE);
  176.             //ScrollWindow(hWnd,0,nVscrollPos, NULL,NULL);
  177.             //UpdateWindow(hWnd);
  178.             }
  179.         }
  180.     else
  181.         {
  182.         if (iPos > ixMax) iPos = ixMax;
  183.         if (iPos < ixMin) iPos = ixMin;
  184.         nHscrollPos = iPos;
  185.         if (nHscrollPos != GetScrollPos(hWnd, SB_HORZ))
  186.             {
  187.             SetScrollPos(hWnd,SB_HORZ, nHscrollPos, TRUE);
  188.             InvalidateRect(hWnd, NULL, TRUE);
  189.             //ScrollWindow(hWnd,nHscrollPos,0, NULL,NULL);
  190.           //    UpdateWindow(hWnd);
  191.             }
  192.         }
  193.     }
  194.